package com.control.thread;

import com.control.activity.MainActivity;
import com.control.utils.StringUtils;
import com.control.wifi.WifiManageClass;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiConfiguration;

public class NetMonitor extends BroadcastReceiver {
	
	public WifiManageClass wifiManageClass = null;
	
	public void onReceive(Context context, Intent intent) {
		wifiManageClass = new WifiManageClass(context);
		checkNetwork();
	}
	
	private void checkNetwork(){
		if(StringUtils.isEmpty(MainActivity.networkId)){
			return;
		}
		
		if(!wifiManageClass.getWifiEnabled()){
			connNetwork();
		}else if(wifiManageClass.getWifiEnabled()){
			if(wifiManageClass.getCurrentNetId() != Integer.parseInt(MainActivity.networkId)){
				wifiManageClass.enableNetwork(Integer.parseInt(MainActivity.networkId),true);
			} 
		}
	}
	
	
	private void connNetwork(){
		WifiConfiguration  wifiConfiguratin = new WifiConfiguration();
		wifiConfiguratin.BSSID = MainActivity.networkId;
		wifiManageClass.AddNetWordLink(wifiConfiguratin);
		//wifiManageClass.enableNetwork(Integer.parseInt(MainActivity.networkId),true);
	}
	
}